package com.google.gwt.demo.client;

import com.google.gwt.demo.client.TestWidget.EnumTest;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;

public class DefaultPresenter implements TestWidget.Presenter{

	private TestWidget testWidget;

	public DefaultPresenter(TestWidget testWidget){
		this.testWidget = testWidget;
	}


	public TestWidget getTestWidget(){
		return testWidget;
	}
	
	@Override
	public void update() {
		if(EnumTest.Choix1.equals(getTestWidget().getProp2())){
			getTestWidget().setText(getTestWidget().getProp1());
		} else {
			getTestWidget().setText("");
		}
	}

	@Override
	public void onWidgetAttach() {
		getTestWidget().sinkEvents(Event.ONCLICK);
	}

	@Override
	public void onWidgetDetach() {
		getTestWidget().unsinkEvents(Event.ONCLICK);
	}


	@Override
	public void onBrowserEvent(Event event) {
		 switch (DOM.eventGetType(event)){
		 	case Event.ONCLICK: ClickEvent.fireNativeEvent(event, getTestWidget());
		 						break;
		 }
	}
}
